// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement.  The various license agreements may be found at
// the Magic Software web site.  This file is subject to the license
//
// FREE SOURCE CODE
// http://www.magic-software.com/License/free.pdf

#ifndef MGCMULTIPLECURVE_H
#define MGCMULTIPLECURVE_H

#include "MgcCurve.h"


template <class Vector>
class MgcMultipleCurve : public MgcCurve<Vector>
{
public:
    // abstract base class
    MgcMultipleCurve (int iSegments, MgcReal* afTime);
    virtual ~MgcMultipleCurve ();

    int GetSegments () const;
    const MgcReal* GetTimes () const;

    virtual MgcReal GetLength (MgcReal fT0, MgcReal fT1) const;
    virtual MgcReal GetTime (MgcReal fLength, int iIterations = 32,
        MgcReal fTolerance = 1e-06) const;

    virtual MgcReal GetVariation (MgcReal fT0, MgcReal fT1,
        const Vector* pkP0 = 0, const Vector* pkP1 = 0) const;

protected:
    int m_iSegments;
    MgcReal* m_afTime;

    // These quantities are allocated by GetLength when they are needed the
    // first time.  The allocations occur in InitializeLength (called by
    // GetLength), so this member function must be 'const'. In order to
    // allocate the arrays in a 'const' function, they must be declared as
    // 'mutable'.
    mutable MgcReal* m_afLength;
    mutable MgcReal* m_afAccumLength;

    void GetKeyInfo (MgcReal fTime, int& riKey, MgcReal& rfDt) const;

    void InitializeLength () const;
    virtual MgcReal GetSpeed (int iKey, MgcReal fTime) const = 0;
    virtual MgcReal GetLength (int iKey, MgcReal fT0, MgcReal fT1) const = 0;
    virtual MgcReal GetVariation (int iKey, MgcReal fT0,
        MgcReal fT1, const Vector& rkA, const Vector& rkB) const = 0;

    static MgcReal GetSpeedWithData (MgcReal fTime, void* pvData);
};

#include "MgcMultipleCurve.inl"

#endif
